﻿using System;
using System.Web.Http;
using ML.Entity;
using ML.IBusiness;

namespace ML.WxLite.WebApi.ChineseRestaurant.Controllers
{
    /// <summary>
    /// 广告api接口
    /// </summary>
    public class AdvertisementController : BaseApiController
    {
        private readonly IAdvertisementBusiness _advertisementBusiness;
        public AdvertisementController(IAdvertisementBusiness advertisementBusiness)
        {
            this._advertisementBusiness = advertisementBusiness;
        }

        /// <summary>
        /// 更新广告信息
        /// </summary>
        /// <returns></returns>
        [Route("api/wxlite/Advertisement/update")]
        [HttpPost]
        public IHttpActionResult Updata(AdvertisementEntity entity)
        {
            var data = _advertisementBusiness.Update(entity);
            return Json(data);
        }

        /// <summary>
        /// 删除广告信息
        /// </summary>
        /// <returns></returns>
        [Route("api/wxlite/Advertisement/delete")]
        [HttpPost]
        public IHttpActionResult Delete(string id)
        {
            var data = _advertisementBusiness.Delete(id);
            return Json(data);
        }

        /// <summary>
        /// 添加广告信息
        /// </summary>
        /// <returns></returns>
        [Route("api/wxlite/Advertisement/add")]
        [HttpPost]
        public IHttpActionResult Add(AdvertisementEntity entity)
        {
            var data = _advertisementBusiness.Add(entity);
            return Json(data);
        }

        /// <summary>
        /// 分页查询广告信息
        /// </summary>
        /// <param name="pageindex">第几页</param>
        /// <param name="pagesize">每页显示多少条</param>
        /// <param name="isDesc">是否升序</param>
        /// <returns></returns>
        [Route("api/wxlite/Advertisement/getlist")]
        [HttpGet]
        public IHttpActionResult GetList(int pageindex=1, int pagesize=10, string summary = "", bool isDesc = false)
        {
            if (pageindex == 0)
            {
                pageindex = 1;
            }
            var data = _advertisementBusiness.List(new AdvertisementSearch { Summary = summary, pagesize = pagesize });
            return Json(data);
        }
    }
}
